<?php

if (isset($_POST['shop_name']) AND isset($_POST['shop_tel']) 
		AND isset($_POST['shop_city']) AND isset($_POST['shop_addr'])
			AND isset($_POST['shop_cp']))
{
	if ($_POST['shop_name'] AND $_POST['shop_tel'] 
			AND $_POST['shop_city'] AND $_POST['shop_addr']
				AND $_POST['shop_cp'])
		{
		if (is_numeric($_POST['shop_tel']) AND is_numeric($_POST['shop_cp']))
			{
				$req = "UPDATE magasins SET VILLE='".$_POST['shop_city']."', TELEPHONE='".$_POST['shop_tel']."',
						ADRESSE='".$_POST['shop_addr']."', CP='".$_POST['shop_cp']."', 
								NOM='".$_POST['shop_name']."', CODE='".$_POST['shop_code']."' WHERE NMAGASIN = ".$_GET['edit_shop_id']."";
				mysql_query($req);
				echo "<p class='box_success'>Informations modifi&eacute;es</p> <br />";
			}
			else
				echo "<p class='box_error'>Le num&eacute;ro de t&eacute;l&eacute;phone ou le code postal ne doivent pas contenir de lettres</p> <br />";
		}
		else
			echo "<p class='box_error'>Certains champs n'ont pas &eacute;t&eacute; remplis </p> <br />";
		
}

global $connect;
$query = "SELECT * FROM magasins WHERE NMAGASIN=".$_GET['edit_shop_id'];
$mag = mysql_query($query, $connect) or die(mysql_error());		
	echo "<center>";
	echo "<div id='add_mag'>";
	echo "<h1> Modifier les informations du magasin </h1> <br />";
	echo "<form action='index.php?page=magasins&action=show_mag&edit_shop_id=".$_GET['edit_shop_id']."' method='post'>";
	echo "<table  border='0' cellspacing='8' cellpadding='40' width='400px'>";
	while ($data = mysql_fetch_array($mag))
	{
		echo "<tr > <td>Nom:</td><td><input type='text' name='shop_name' value='".$data['NOM']."'/></td> </tr>";
		echo "<tr > <td>Code Magasin:</td><td><input type='text' name='shop_code' value='".$data['CODE']."'/></td> </tr>";
		echo "<tr> <td>Adresse :</td><td><input type='text' name='shop_addr' value='".$data['ADRESSE']."'/></td> </tr>";
		echo "<tr> <td>Ville :</td><td><input type='text' name='shop_city' value='".$data['VILLE']."'/></td> </tr>";
		echo "<tr> <td>Code postal :</td><td><input type='text' name='shop_cp' value='".$data['CP']."'/></td> </tr>";
		echo "<tr> <td>Telephone :</td> <td><input type='text' name='shop_tel' value='".$data['TELEPHONE']."'/></td> </tr>";
		echo "<tr><td></td><td><input type='submit' value='Modifier'></td></tr>";
	}
	echo "</table>";
	echo "<br />";
echo "</form>";
echo "</div>";
echo "</center>";
echo "<h1><center><a href='index.php?page=magasins'><img src='img/jamembo-back.png' width='30px' height='30px'/> Retour a la liste des magasins</a></center></h1>";

?>